<?php
namespace app\tools\logic;
use think\facade\Db;

class SoftLogic{
	static function getList(){
		$page_size = input('page_size', 10);
		$soft_name = input('soft_name','');

		$obj = Db::name('soft_ware')
				->where('status','<>',127);
		$soft_name && $obj->where('soft_name','like','%'.$soft_name.'%');
		$list = $obj->order('sort asc, id desc')
				->paginate($page_size);
		return $list;
	}

	static function getInfo(){
		$id = input('id');
		if(!$id){
			return '';
		}
		$info = Db::name('soft_ware')
					->where('id', $id)
					->find();
		return $info;

	}

	static function save(){
		$id = input('id');
		if(!$id){
			return 110;
		}
		$data = [];
		$data['soft_name'] = input('soft_name','');
		$data['soft_name_en'] = input('soft_name_en','');
		$data['web_disk_url'] = input('web_disk_url', '');
		$data['password'] = input('password', '');
		$data['sort'] = input('sort', 50);
		$data['status'] = input('status', 1);
		$data['remakr'] = input('remakr', "");
		$data['remark_en'] = input('remark_en', "");
		// $data['create_time'] = input('create_time', 0);



		$rs = Db::name('soft_ware')
				->where('id', $id)
				->update($data);
		if($rs!==false){
			return 0;
		}else{
			return 100000;
		}
	}

	static function add(){
		$data = [];
		$data['soft_name'] = input('soft_name','');
		$data['soft_name_en'] = input('soft_name_en','');
		$data['web_disk_url'] = input('web_disk_url', '');
		$data['password'] = input('password', '');
		$data['sort'] = input('sort', 50);
		$data['status'] = input('status', 1);
		$data['remakr'] = input('remakr', "");
		$data['remark_en'] = input('remark_en', "");
		$data['create_time'] = date('Y-m-d H:i:s');

		$rs = Db::name('soft_ware')->insert($data);
		if($rs!==false){
			return 0;
		}else{
			return 100000;
		}
	}

	//删除
	static function delete(){
		$id = input('id','');
		$ids = explode(',', $id);
		if(!$ids || !$id){
			return 110;
		}
		$rs = Db::name('soft_ware')
				->where('id','in', $ids)
				->update(['status'=>127]);
		if($rs!==false){
			return 0;
		}else{
			return 100000;
		}
	}
}